package com.iven.xie.code.generator.bean;

import lombok.Data;
import org.springframework.http.HttpStatus;

/**
 * @author iven.xie
 */
@Data
public class ResObject<T> {
    private int code;
    private T data;
    private String desc;
    private String msg;

    public static ResObject success(Object data) {
        return ResObject.success("操作成功", data);
    }

    private static ResObject success(String msg, Object data) {
        ResObject resObject = new ResObject();
        resObject.setCode(HttpStatus.OK.value());
        resObject.setMsg(msg);
        resObject.setData(data);
        return resObject;
    }

    public static ResObject error() {
        return error(500, "未知异常，请联系管理员");
    }

    public static ResObject error(String msg) {
        return error(500, msg);
    }

    public static ResObject error(int code, String msg) {
        ResObject resObject = new ResObject();
        resObject.setCode(code);
        resObject.setMsg(msg);
        return resObject;
    }

    public static ResObject success() {
        return ResObject.success("操作成功", null);
    }
}
